package com.partybuilding.handler.exception;


import com.mysql.cj.log.Log;
import com.partybuilding.domain.ResponseResult;
import com.partybuilding.enums.AppHttpCodeEnum;
import com.partybuilding.expection.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExpectionHandler(SystemException e){
        //打印异常信息
         log.error("出现异常！{}",e);
        //从异常对象中获取提示信息封装返回
        return ResponseResult.errorResult(e.getCode(),e.getMsg());

    }


    @ExceptionHandler(Exception.class)
    public ResponseResult expectionHandler(Exception e){
        //打印异常信息
        log.error("出现异常！{}",e);
        //从异常对象中获取提示信息封装返回
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR.getCode(),e.getMessage());

    }

}
